/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.manager.CompanyStatusManager;
/*     */ import com.newcrm.thread.LuceneThread;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class AddUpdatePeople extends AbstractAddUpdateCustomerDeal
/*     */ {
/*  25 */   private int id = 0;
/*  26 */   private String indexPath = null;
/*  27 */   private static Logger logger = Logger.getLogger(AddUpdatePeople.class
/*  28 */     .getName());
/*     */ 
/*     */   public AddUpdatePeople(AbstractHttpServlet servlet, String id, String indexPath)
/*     */   {
/*  32 */     super(servlet);
/*  33 */     this.id = Util.str2Int(id);
/*  34 */     this.indexPath = indexPath;
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException
/*     */   {
/*  43 */     if (!CompanyStatusManager.getInstance().getAddCompanyStatus()) {
/*  44 */       response.sendRedirect(request.getContextPath() + "/parties");
/*  45 */       return;
/*     */     }
/*     */ 
/*  48 */     User loginUser = super.getLoginUser(request);
/*  49 */     String userId = loginUser.userId;
/*  50 */     int companyId = loginUser.companyId;
/*     */ 
/*  52 */     String peopleName = Util.getURLParameter(request
/*  53 */       .getParameter("peopleName"));
/*  54 */     if ((peopleName == null) || (peopleName.trim().length() == 0)) {
/*  55 */       if (this.id <= 0)
/*  56 */         response.sendRedirect(request.getContextPath() + "/people/new");
/*     */       else {
/*  58 */         response.sendRedirect(request.getContextPath() + "/people/" + 
/*  59 */           this.id);
/*     */       }
/*  61 */       logger.warn("peopleName is null");
/*  62 */       return;
/*     */     }
/*  64 */     String peopleTitle = Util.getURLParameter(request
/*  65 */       .getParameter("peopleTitle"));
/*     */ 
/*  67 */     String peopleNote = Util.getURLParameter(request
/*  68 */       .getParameter("background"));
/*  69 */     List extInfos = new ArrayList();
/*     */ 
/*  71 */     addExtInfo(request, "phone", extInfos, 
/*  72 */       1);
/*     */ 
/*  74 */     addExtInfo(request, "email", extInfos, 
/*  75 */       2);
/*     */ 
/*  77 */     addExtInfo(request, "im", extInfos, 
/*  78 */       3);
/*     */ 
/*  80 */     addExtInfo(request, "website", extInfos, 
/*  81 */       4);
/*     */ 
/*  83 */     addExtInfo(request, "weibo", extInfos, 
/*  84 */       5);
/*     */ 
/*  86 */     addExtInfo(request, "address", extInfos, 
/*  87 */       6);
/*     */ 
/*  90 */     int oldBelongCustomerId = Util.getURLIntParameter(request
/*  91 */       .getParameter("oldCompanyId"));
/*  92 */     String companyName = Util.getURLParameter(request
/*  93 */       .getParameter("companyName"));
/*     */ 
/*  96 */     int visible = Util.getURLIntParameter(request.getParameter("visible"));
/*  97 */     String permissionsId = "";
/*  98 */     String shareUserIds = "";
/*  99 */     String shareGroupIds = "";
/*     */ 
/* 102 */     if (visible == 1) {
/* 103 */       permissionsId = Util.getURLParameter(request
/* 104 */         .getParameter("groupPermissionsId"));
/* 105 */     } else if (visible == 4)
/*     */     {
/* 107 */       permissionsId = Util.getURLParameter(request
/* 108 */         .getParameter("permissionsId"));
/* 109 */       shareUserIds = StringUtils.join(
/* 110 */         request.getParameterValues("shareUserId"), ",");
/* 111 */       shareGroupIds = StringUtils.join(
/* 112 */         request.getParameterValues("shareGroupId"), ",");
/*     */     }
/*     */ 
/* 116 */     super.addFieldInfo(request, extInfos);
/*     */ 
/* 118 */     CustomerManager manager = new CustomerManager();
/*     */ 
/* 121 */     if (this.id <= 0) {
/* 122 */       this.id = manager.addPeople(companyName, peopleName, peopleTitle, 
/* 123 */         -1, peopleNote, visible, permissionsId, shareUserIds, 
/* 124 */         shareGroupIds, null, extInfos, userId, companyId);
/*     */ 
/* 126 */       String returnUrl = Util.getURLParameter(request
/* 127 */         .getParameter("returnUrl"));
/*     */ 
/* 129 */       if ((returnUrl == null) || (returnUrl.trim().length() == 0)) {
/* 130 */         response.sendRedirect(request.getContextPath() + "/people/" + 
/* 131 */           this.id);
/* 132 */         return;
/*     */       }
/*     */ 
/* 136 */       new LuceneThread(this.indexPath, false).start();
/*     */ 
/* 138 */       response.sendRedirect(returnUrl);
/* 139 */       return;
/*     */     }
/*     */ 
/* 142 */     int oldVisible = Util.getURLIntParameter(request
/* 143 */       .getParameter("oldVisible"));
/* 144 */     String oldPermissionsId = Util.getURLParameter(request
/* 145 */       .getParameter("oldPermissionsId"));
/* 146 */     String oldShareUserIds = Util.getURLParameter(request
/* 147 */       .getParameter("oldShareUserIds"));
/* 148 */     String oldShareGroupIds = Util.getURLParameter(request
/* 149 */       .getParameter("oldShareGroupIds"));
/* 150 */     int hasModifyRight = Util.getURLIntParameter(request
/* 151 */       .getParameter("hasModifyRight"));
/* 152 */     if (hasModifyRight == 0)
/*     */     {
/* 154 */       visible = oldVisible;
/* 155 */       permissionsId = oldPermissionsId;
/* 156 */       shareUserIds = oldShareUserIds;
/* 157 */       shareGroupIds = oldShareGroupIds;
/*     */     }
/*     */ 
/* 161 */     String deleteExtInfoIds = request.getParameter("deleteExtInfoIds");
/* 162 */     manager.updatePeople(oldBelongCustomerId, companyName, this.id, 
/* 163 */       peopleName, peopleTitle, -1, peopleNote, hasModifyRight, 
/* 164 */       visible, permissionsId, oldPermissionsId, shareUserIds, 
/* 165 */       oldShareUserIds, shareGroupIds, oldShareGroupIds, null, false, 
/* 166 */       extInfos, deleteExtInfoIds, userId, companyId);
/*     */ 
/* 169 */     new LuceneThread(this.indexPath, false).start();
/*     */ 
/* 171 */     response.sendRedirect(request.getContextPath() + "/people/" + this.id);
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.AddUpdatePeople
 * JD-Core Version:    0.6.1
 */